package components.contorls.superClass
{
    import components.core.UIComponent;
    import components.utils.EventListenerUtil;

    import flash.events.Event;

    import mx.events.ResizeEvent;

    public class BaseToolTip extends UIComponent
    {
        private var _data:Object;

        private var _dataChange:Boolean;

        private var _maxWidth:Number = NaN;

        private var _labelInitLeft:Number;

        private var _labelInitTop:Number;

        private var _labelInitRight:Number;

        private var _labelInitBottom:Number;

        public function BaseToolTip()
        {
            super();

            focusEnable = false;
        }


        protected override function frameConstructedHandler(event:Event):void
        {
            super.frameConstructedHandler(event);

			if(labelTF)
            	EventListenerUtil.addEventListener(labelTF, ResizeEvent.RESIZE, label_resizeHandler, false, 0, true);
        }


        /***************************************
         *
         * 显示对象声明
         *
         * **************************************/

        public function get labelTF():BaseLabel
        {
            return getChildByName("labelSkin") as BaseLabel;
        }

        /***************************************
         *
         * 验证
         *
         * **************************************/

        protected override function commitProperties():void
        {
            super.commitProperties();

            if (!_initialized && labelTF)
            {
                _labelInitLeft = labelTF.x;
                _labelInitTop = labelTF.y;
                _labelInitRight = _normalWidth - labelTF.x - labelTF.width;
                _labelInitBottom = _normalHeight - labelTF.y - labelTF.height;

                labelTF.width = width - _labelInitLeft - _labelInitRight;
            }

            if (labelTF)
            {
                if (_dataChange)
                {
					labelTF.width=labelTF.height = 100000;
                    labelTF.text = String(data);
                    labelTF.validateNow();
                    _dataChange = false;

                    width = labelTF.textSp.width + _labelInitLeft + _labelInitRight;
                    height = labelTF.textSp.height + _labelInitTop + _labelInitBottom;
                }
            }
        }

        protected override function measureSizes():Boolean
        {
            return super.measureSizes();
        }

        protected override function updateDisplayList():void
        {
            super.updateDisplayList();
        }

        /***************************************
         *
         * 组件定义
         *
         * **************************************/

        /***************************************
         *
         * 其他代码
         *
         * **************************************/

        public function get data():Object
        {
            return _data;
        }

        public function set data(value:Object):void
        {
            _data = value;
            _dataChange = true;
            invalidate();
        }

        public override function set focusEnable(value:Boolean):void
        {
            super.focusEnable = value;

            if (labelTF)
                labelTF.focusEnable = false;
        }

        public override function destroy():void
        {
            super.destroy();
            _data = null;
        }

        public override function validateNow():void
        {
            super.validateNow();
			if(labelTF)
            	labelTF.validateNow();
        }

        protected function label_resizeHandler(event:ResizeEvent):void
        {
            invalidate();
        }
    }
}
